package com.easyattendance.model;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name="tbl_section")
public class Section {
	
	 @Id
	 @GenericGenerator(name="section_id",strategy="foreign")
	 @Column(name="section_id",length=10,nullable=false)
	 private String section_id;
	 
	 @Column(name="section_name",length=32,nullable=false)
	 private String section_name;
	 
	 @Column(name="term_end_date",nullable=false)
	 private Date term_end_date;
		
	 @Column(name="term_start_date",nullable=false)
	 private Date term_start_date;
	 
	 @GenericGenerator(name="email_id",strategy="foreign")
	 @Column(name="email_id",length=50,nullable=false,unique=true)
	 private String email_id;
	 
	 /* One to one mapping  */

		@OneToOne(optional=false)
		//@OnDelete(action=OnDeleteAction.CASCADE)
		@PrimaryKeyJoinColumn
		private User user;
		
		@OneToOne(optional=false,fetch=FetchType.LAZY)
		@JoinColumn(name="email_id", insertable=false, updatable=false, referencedColumnName="email_id")
		private User user1;
		
		/* One To Many mappings of Department */
		
		@OneToMany(mappedBy="section")
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<Class> classes;

		@OneToMany(mappedBy="section")
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<Teacher> teachers;
		
		@OneToMany(mappedBy="section")
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<Subject> subjects;
		
		@OneToMany(mappedBy="section")
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<Student> students;
		
		@OneToMany(mappedBy="section")
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<TimeSlot> timeSlots;
		
		@OneToMany(mappedBy="section")
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<TimeTable> timeTable;
		
		@OneToMany(mappedBy="section")
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<EmailSettings> emailSettings;
		
		@OneToMany(mappedBy="section")
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<Holidays> holidays;
		
		@OneToMany(mappedBy="section", fetch=FetchType.LAZY)
		@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
		private Set<MaterialSection> materialSection;
		
		public Section()
		{
			
		}

		public Section(String section_id, String section_name,String section_email) {
			super();
			this.section_id = section_id;
			this.section_name = section_name;
			this.email_id=section_email;
		}

		
	public Section(String section_name, String section_email_id) {
			super();
			this.section_name = section_name;
			this.email_id = section_email_id;
		}
	
		

		public Section(String section_id, String section_name,String email_id,
			Date term_start_date, Date term_end_date) {
		super();
		this.section_id = section_id;
		this.section_name = section_name;
		this.email_id = email_id;
		this.term_start_date = term_start_date;
		this.term_end_date = term_end_date;		
	}

		public String getSection_id() {
			return section_id;
		}

		public void setSection_id(String section_id) {
			this.section_id = section_id;
		}

		public String getSection_name() {
			return section_name;
		}

		public void setSection_name(String section_name) {
			this.section_name = section_name;
		}
		
		public User getUser() {
			return user;
		}

		public void setUser(User user) {
			this.user = user;
		}

		public String getEmail_id() {
			return email_id;
		}

		public void setEmail_id(String email_id) {
			this.email_id = email_id;
		}

		public User getUser1() {
			return user1;
		}

		public void setUser1(User user1) {
			this.user1 = user1;
		}

		public Set<Class> getClasses() {
			return classes;
		}

		public void setClasses(Set<Class> classes) {
			this.classes = classes;
		}

		public Set<Teacher> getTeachers() {
			return teachers;
		}

		public void setTeachers(Set<Teacher> teachers) {
			this.teachers = teachers;
		}

		public Set<Subject> getSubjects() {
			return subjects;
		}

		public void setSubjects(Set<Subject> subjects) {
			this.subjects = subjects;
		}

		public Set<Student> getStudents() {
			return students;
		}

		public void setStudents(Set<Student> students) {
			this.students = students;
		}

		public Set<TimeSlot> getTimeSlots() {
			return timeSlots;
		}

		public void setTimeSlots(Set<TimeSlot> timeSlots) {
			this.timeSlots = timeSlots;
		}

		public Set<TimeTable> getTimeTable() {
			return timeTable;
		}

		public void setTimeTable(Set<TimeTable> timeTable) {
			this.timeTable = timeTable;
		}

		public Set<EmailSettings> getEmailSettings() {
			return emailSettings;
		}

		public void setEmailSettings(Set<EmailSettings> emailSettings) {
			this.emailSettings = emailSettings;
		}
		
		public Date getTerm_end_date() {
			return term_end_date;
		}

		public void setTerm_end_date(Date term_end_date) {
			this.term_end_date = term_end_date;
		}

		public Date getTerm_start_date() {
			return term_start_date;
		}

		public void setTerm_start_date(Date term_start_date) {
			this.term_start_date = term_start_date;
		}

		public Set<Holidays> getHolidays() {
			return holidays;
		}

		public void setHolidays(Set<Holidays> holidays) {
			this.holidays = holidays;
		}

		public Set<MaterialSection> getMaterialSection() {
			return materialSection;
		}

		public void setMaterialSection(Set<MaterialSection> materialSection) {
			this.materialSection = materialSection;
		}
	
}
